package com.xlkj.ms.tools.core.response;

import com.xlkj.ms.tools.core.model.Data;

import java.util.List;

/**
 * 带status的响应包装类
 * <pre>
 * {@code
 * {
 *     "status":true,
 *     "code":"***",
 *     "msg":"****",
 *     "data":{
 *         "page_size":***,
 *         "total_size":***,
 *         "items":[{***}]
 *     }
 *     "redirect":"***"
 * }
 * }
 * </pre>
 * @author zhuqifeng
 * @date 2021/11/10 13:56
 * @package com.xlkj.ms.tools.core.response
 */
public abstract class AbstractPageWithStatusResponseWrapper<E> extends AbstractResponse{


    private static final long serialVersionUID = -4606848742088955637L;

    private boolean status;

    private String redirect;

    private DataPage<E> data;

    public AbstractPageWithStatusResponseWrapper(){}

    public AbstractPageWithStatusResponseWrapper(boolean status, String redirect, DataPage<E> data) {
        this.status = status;
        this.redirect = redirect;
        this.data = data;
    }

    @Override
    public void wrapperSuccess() {
        this.status = true;
        super.wrapperSuccess();
    }

    @Override
    public void wrapperSystemError() {
        this.status = false;
        super.wrapperSystemError();
    }

    @Override
    public void wrapperIllegalArgument(String... illegalArguments) {
        this.status = false;
        super.wrapperIllegalArgument(illegalArguments);
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public String getRedirect() {
        return redirect;
    }

    public void setRedirect(String redirect) {
        this.redirect = redirect;
    }

    public DataPage<E> getData() {
        return data;
    }

    public void setData(DataPage<E> data) {
        this.data = data;
    }

    public static class DataPage<E> extends Data {

        private static final long serialVersionUID = 7204139401804336672L;

        private long page_size;

        private long total_size;

        private List<E> items;

        public DataPage() {
        }

        public long getPage_size() {
            return page_size;
        }

        public void setPage_size(long page_size) {
            this.page_size = page_size;
        }

        public long getTotal_size() {
            return total_size;
        }

        public void setTotal_size(long total_size) {
            this.total_size = total_size;
        }

        public List<E> getItems() {
            return items;
        }

        public void setItems(List<E> items) {
            this.items = items;
        }
    }
}